<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        table{
            border-collapse: collapse;
            width: 500px;
            height: 300px;
            text-align: center;
            margin: 50px auto;
        }
        table,td,tr,th{
            border: 1px solid palegoldenrod;
        }
        td{
            width: 100px;
            height: 50px;
            line-height: 50px;
            text-align: center;
        }
    </style>
</head>
<body>
    <table>
        <thead>
                <td>ID</td>
                <td>商品</td>
                <td>价格</td>
                <td>数量</td>
                <td>包邮</td>
        </thead>
        <tfoot id="tf">
            <tr>
                <td colspan="5">总计：<span id="span"></span></td>
            </tr>
        </tfoot>
    </table>
    <script>
        var list = [
            {ID:'1',name:'小潘1号',pc:'19.9',num:'100',by:'是'},
            {ID:'2',name:'小潘2号',pc:'19.9',num:'100',by:'是'},
            {ID:'3',name:'小潘3号',pc:'19.9',num:'100',by:'是'},
            {ID:'4',name:'小潘4号',pc:'19.9',num:'100',by:'是'}
        ]
        var table = document.querySelector('table')
        var span = document.querySelector('#span')
        var tfoot = document.querySelector('#tf')
        var tbody = document.createElement('tbody');
        for(var i=0;i<list.length;i++){
            var tr = document.createElement('tr')
            for(var key in list[i]){
               var td = document.createElement('td')
               td.innerHTML = list[i][key]
               tr.appendChild(td)  
            }
            tbody.appendChild(tr)
        }
        table.insertBefore(tbody,tfoot)

        var money = list.reduce(function(result,p){
            result = p.pc*p.num +result
            return result
        },0)

        span.innerHTML = Math.round(money)
        
    </script>
</body>
</html>